/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package midpmpc;

import midpmpc.ui.MenuOption;
import org.j4me.logging.Log;
import org.j4me.ui.Dialog;
import org.j4me.ui.Menu;
import org.j4me.ui.MenuItem;
import org.j4me.ui.components.Label;

/**
 *
 * @author vvs
 */
public class FileListView extends Dialog {

    FileInfo[]files;
    Mpc _parent;
    int pos=0;
    int len=10;
    class FileItem implements MenuItem
    {
        String _text;
        FileListView flv;
        public FileItem(String text,FileListView parent)
        {
            _text=text;
        }
        public String getText()
        {
            return _text;
        }
        public void onSelection()
        {
        }
    }
    public FileListView(Mpc parent)
    {
        _parent=parent;
    }
    public void setFiles(FileInfo []fl)
    {
        if (fl==null)
            return;
        files=fl;
        deleteAll();
//        for (int i=0;i<fl.length;i++)
        for (int i=0;i<fl.length;i++)
        {
//            if (i+pos<fl.length)
//            {
//                Log.warn("set: "+String.valueOf(i+pos));
            append(new midpmpc.ui.MenuOption(formatFile(fl[i])));
//            }
        }
    }
    String formatFile(FileInfo f)
    {
        return f.artist + " - " + f.title;
    }
    public String currentId()
    {
        Log.warn("selected "+files[getSelected()].file);
        return files[getSelected()].id;

    }
    public String currentFile()
    {
        return files[getSelected()].file;
    }
    public void keyPressed(int key)
    {
        if (key==MENU_RIGHT)
        {
            _parent.main.show();
        }
        else if (key==RIGHT)
        {
            int cn=getSelected();
//            Log.warn("cn "+cn);
            if (cn<files.length-11)
                cn+=10;
            else
                cn=files.length-1;
//            Log.warn("cn2 "+cn);
            setSelected(cn);
            repaint();
        }
        else if (key==LEFT)
        {
            int cn=getSelected();
            if (cn>10)
                cn-=10;
            else
                cn=0;
            setSelected(cn);
            repaint();
        }
        else if (key==UP && getSelected()==0)
        {
            setSelected(files.length-1);
            repaint();
        }
        else if (key==DOWN && getSelected()==files.length-1)
        {
            setSelected(0);
            repaint();
        }
        else
        {


            super.keyPressed(key);
        }
            
    }
    void itemSelected()
    {
    }
//    public int getSelected()
//    {
//        return super.getSelected()+pos;
//    }

}
